<template>
  <div class="contact-us">
    <!-- 标题部分 -->
    <div class="name">
      <h1>联系我们</h1>
      <h3>contact-us</h3>
    </div>
    <!-- 卡片容器 -->
    <div class="box-wrap">
      <!-- 确保 CompanyList 有数据并且不为空 -->
      <template v-if="CompanyList.length > 0">
        <!-- 网址卡片 -->
        <el-card class="box-card">
          <div class="card-content">
            <img src="../assets/internet.png" alt="网站图标" class="icon" />
            <div class="info-item">
              <div class="info-content">
                <p class="label">公司网址</p>
                <el-link type="primary" @click="openUrl(CompanyList[0].CompanyNetWork)">
                  {{ CompanyList[0].CompanyNetWork }}
                </el-link>
              </div>
            </div>
            <div class="qrcode">
              <!-- 确保 WechatQRCode 存在 -->
              <el-image
                v-if="CompanyList[0].WechatQRCode"
                style="width: 100px; height: 100px"
                :src="CompanyList[0].WechatQRCode"
                fit="fill"
              />
              <span v-else>二维码加载中...</span>
            </div>
          </div>
        </el-card>
        <!-- 电话卡片 -->
        <el-card class="box-card" style="width:360px">
          <div class="card-content">
            <img src="../assets/phone.png" alt="电话图标" class="icon" />
            <div class="info-item">
              <div class="info-content">
                <p class="label">联系电话</p>
                <span>{{ CompanyList[0].Phone }}</span>
              </div>
            </div>
          </div>
        </el-card>
        <!-- 地址卡片 -->
        <el-card class="box-card">
          <div class="card-content">
            <img src="../assets/location.png" alt="地址图标" class="icon" />
            <div class="info-item">
              <div class="info-content">
                <p class="label">公司地址</p>
                <span>{{ CompanyList[0].Address }}</span>
              </div>
            </div>
          </div>
        </el-card>
      </template>
      <!-- 数据加载中的提示 -->
      <div v-else>
        加载中...
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue';
import {connrequest} from "../api/connrequest";

const CompanyList = ref([]);

onMounted(async () => {
  try {
    const res = await connrequest("GetContactUS");
    if (res && res.Status && res.Status.StatusCode === 0) {
      CompanyList.value = res.Data;
    } 
  } catch (error) {
    console.error("请求过程中发生错误:", error);
  }
});

const openUrl = (url) => {
  window.open(url, "_blank");
};
</script>

<style lang="scss" scoped>
.contact-us {
  width: calc(100vw - 125px);
  height: calc(100vh - 70px);
  overflow-y: auto;
  background: #fff;
  padding: 20px;
  margin: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;

  .name {
    position: relative;
    text-align: center;
    top:5%;
    h1 {
      margin: 0;
      font-size: 28px;
      font-weight: bold;
    }
    h3 {
      margin: 0 0 40px;
      font-size: 20px;
    }
  }

  .box-wrap {
    display: flex;
    justify-content: center; /* 水平居中 */
    align-items: center; /* 垂直居中 */
    gap: 20px; /* 卡片之间的间距 */
    height: 30vh; /* 确保父容器有高度 */
  }

  .box-card {
    width: 460px; /* 固定卡片宽度 */
    height: 180px; /* 固定卡片高度 */
    display: flex;
    align-items: center; /* 垂直居中 */
    justify-content: flex-start; /* 内容向左对齐 */
    margin-left: 15px;
  }
  .box-card ::v-deep(.el-card__body) {
    padding: 0 !important; /* 移除内边距 */
    height: 100%; /* 继承卡片高度 */
    display: flex;
    align-items: center;
    justify-content: flex-start; /* 内容向左对齐 */
  }
  .card-content {
    display: flex;
    align-items: center; /* 垂直居中 */
    justify-content: flex-start; /* 内容向左对齐 */
    width: 100%; /* 占满父容器宽度 */
    padding-left: 20px; /* 左侧留白 */
  }
  .icon {
    width: 50px; /* 图标宽度 */
    height: 50px; /* 图标高度 */
    margin-right: 10px; /* 图标与文字的间距 */
  }
  .info-content {
    line-height: 1.5; /* 保持文字行高 */
    text-align: left; /* 文字向左对齐 */
    p {
      margin: 0; /* 移除段落默认外边距 */
      display: block; /* 强制span独占一行 */
      font-size: 20px;
      font-weight:bold;
    }
    .el-link {
      display: block; /* 强制el-link独占一行 */
      margin-top: 5px; /* 添加一些间距，使两行更自然 */
      font-size: 18px;
    }
  }
  .qrcode {
    margin-left: 28px; /* 二维码靠右 */
  }
}
.night {
  .contact-us {
    background: #363b4d;
  }
  .el-card {
    background: #ccc;
    border:1px solid rgba(42, 77, 105, 0.5);
    background:inset 0 1px 2px rgba(255, 255, 255, 0.1);
  }
  .name{
    color: #ccc;
  }
}
</style>